//var store vertext shader color info
varying lowp vec4 frag_Color;
//var store texture coord from vertext shader
varying lowp vec2 frag_TexCoord;
//var store normal from vertext shader
varying lowp vec3 frag_Normal;
//var store eye position from vertext shader
varying lowp vec3 frag_Position;

//var store Texture
uniform sampler2D u_Texture;
//var storee Specular Intensity
uniform highp float u_MatSpecularIntensity;
//var storee Shininess
uniform highp float u_Shininess;
//define Light
struct Light {
    lowp vec3 Color;//color
    lowp float AmbientIntensity;//light times
    lowp float DiffuseIntensity;//diffuse times
    lowp vec3  Direction;//light direction
};
//unfor stroe light
uniform Light u_Light;
void main(void) {
// set value for each fragment with vetex color
    //get the color of texCoord Texture :texture2D(u_Texture, frag_TexCoord)
    lowp vec3 AmbientColor = u_Light.Color * u_Light.AmbientIntensity;
    
    // Diffuse
    lowp vec3 Normal = normalize(frag_Normal);
    lowp float DiffuseFactor = max(-dot(Normal,u_Light.Direction), 0.0);
    lowp vec3 DiffuseColor = u_Light.Color * u_Light.DiffuseIntensity * DiffuseFactor;
    
    // Specular
    lowp vec3 Eye = normalize(frag_Position);
    lowp vec3 Reflection = reflect(u_Light.Direction, Normal);
    lowp float SpecularFactor = pow(max(0.0, -dot(Reflection, Eye)), u_Shininess);
    
    lowp vec3 SpecularColor = u_Light.Color * u_MatSpecularIntensity * SpecularFactor;
    gl_FragColor =  texture2D(u_Texture, frag_TexCoord) * vec4((AmbientColor + DiffuseColor + SpecularColor), 1.0);
//    gl_FragColor = vec4(1,1,1,1);
}
